package com.ansion.basedb.database;

import android.text.TextUtils;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.ansion.constant.BConstant;
import com.ansion.log.VLog;
import com.ansion.utils.GsonUtil;
import java.util.HashMap;

public class TrackHelper {

    public static void trackDBSaveError(@NonNull String message, @Nullable Exception exception, String uid) {
        HashMap<String, String> params = new HashMap<>();
        params.put(BConstant.FootPrint.EVENT, BConstant.FootPrint.E2EE.TRACK_EVENT_NAME);
        params.put(BConstant.FootPrint.AppFetalArgument.REASON, BConstant.FootPrint.E2EE.REASON_Key_Store_Error);
        HashMap<String, String> ext = new HashMap<>();
        ext.put(BConstant.FootPrint.AppFetalArgument.ErrorMessage, String.format("DBSaveError message:%s,errorMsg:%s", message, exception != null ? exception.getMessage() : ""));
        ext.put(BConstant.FootPrint.E2EEArguments.Uid, uid);
        params.put(BConstant.FootPrint.AppFetalArgument.EXT, GsonUtil.GsonString(ext));
//        AppBridge.appInterface().track(BConstant.FootPrint.kAPPFatal, params);
        VLog.d("TAG_TRACK", "trackDBSaveError [%s-%s]", BConstant.FootPrint.E2EE.REASON_Key_Store_Error, message);
    }

    public static void trackError(@NonNull String event, @NonNull String reason, @NonNull String errorMsg, String uid) {
        VLog.d("TAG_TRACK", "trackError [%s-%s]", reason, errorMsg);
        HashMap<String, String> params = new HashMap<>();
        params.put(BConstant.FootPrint.EVENT, event);
        params.put(BConstant.FootPrint.AppFetalArgument.REASON, reason);
        if (!TextUtils.isEmpty(errorMsg)) {
            HashMap<String, String> ext = new HashMap<>();
            ext.put(BConstant.FootPrint.AppFetalArgument.ErrorMessage, errorMsg);
            ext.put(BConstant.FootPrint.E2EEArguments.Uid, uid);
            params.put(BConstant.FootPrint.AppFetalArgument.EXT, GsonUtil.GsonString(ext));
        }
//        AppBridge.appInterface().track(BConstant.FootPrint.kAPPFatal, params);
        VLog.d("TAG_TRACK", "trackError [%s-%s]", reason, errorMsg);
    }
}
